<template>
  <span class="text-right">
    <el-button size="mini" type="default" @click="copy"
      ><span class="fa fa-copy tag-read" :data-clipboard-text="waybillNo">
        批量复制运单号</span
      ></el-button
    >
  </span>
</template>

<script>
import axios from "axios";
import * as constant from "@/store/yg/common/constant";
import Clipboard from "clipboard";
export default {
  data() {
    return {
      waybillNo: "",
      arr: []
    };
  },

  methods: {
    copy() {
      // console.log(this.$store.state.main.selectedRows);
      // console.log(this.$store.state.main.selectedData);
      this.arr = [];
      this.waybillNo = "";
      this.arr = this.$store.state.main.selectedData;
      if (this.arr.length > 0) {
        for (let i of this.arr) {
          this.waybillNo += i.waybillNo + "\n";
        }
        console.log("this.waybillNo: ", this.waybillNo);
        const clipboard = new Clipboard(".tag-read");
        clipboard.on("success", e => {
          this.$message.success("复制成功");
          // 释放内存
          clipboard.destroy();
        });
        clipboard.on("error", e => {
          // 不支持复制
          this.$message.error("该浏览器不支持自动复制");
          // 释放内存
          clipboard.destroy();
        });
      } else {
        return this.$message.error("请先勾选运单再复制");
      }
    }
  },
  mounted() {}
};
</script>

<style></style>
